import { useAuthStore } from '@/store';
import type { Router } from 'vue-router';

export function setupPageGuard(router: Router) {
  router.beforeEach(async (to, from, next) => {
    if (to.path === '/login') {
      next();
      return;
    }
    const authStore = useAuthStore();
    if (!authStore.token) {
      next({ name: 'login' });
    } else {
      next();
    }
  });
}
